import java.util.PriorityQueue;

/**
 * @author Sebastian
 * @version 2.0
 * @date 2024/8/12 10:27
 */
// 数组中的第K个最大元素
    // https://leetcode.cn/problems/kth-largest-element-in-an-array/
public class Solution215 {
    public int findKthLargest(int[] nums, int k) {
        PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
        for (int num : nums) {
            pq.offer(num);
            if (pq.size() > k) {
                pq.poll();
            }
        }
        return pq.peek();
    }
}
